package com.dp.mallchat.common.user.controller;


import com.dp.mallchat.common.common.domain.dto.RequestInfo;
import com.dp.mallchat.common.common.domain.vo.req.CursorPageBaseReq;
import com.dp.mallchat.common.common.domain.vo.req.PageBaseReq;
import com.dp.mallchat.common.common.domain.vo.resp.ApiResult;
import com.dp.mallchat.common.common.domain.vo.resp.CursorPageBaseResp;
import com.dp.mallchat.common.common.domain.vo.resp.PageBaseResp;
import com.dp.mallchat.common.common.utils.RequestHolder;
import com.dp.mallchat.common.user.domain.user.req.ApplyApprovalReq;
import com.dp.mallchat.common.user.domain.user.req.FriendApplyReq;
import com.dp.mallchat.common.user.domain.user.req.FriendCheckReq;
import com.dp.mallchat.common.user.domain.user.resp.FriendCheckResp;
import com.dp.mallchat.common.user.domain.user.resp.FriendUnreadResp;
import com.dp.mallchat.common.user.domain.user.resp.UserApplyPageResp;
import com.dp.mallchat.common.user.service.UserApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;

/**
 * <p>
 * 用户申请表 前端控制器
 * </p>
 *
 * @author <a href="https://gitee.com/baiDP">adu</a>
 * @since 2024-06-19
 */
@RestController
@RequestMapping("/capi/user/friend/apply")
@Api(value = "用户申请相关接口", tags = "用户申请相关接口")
public class UserApplyController {

    @Autowired
    private UserApplyService userApplyService;

    @ApiOperation("校验是否为自己好友")
    @GetMapping("/check")
    public ApiResult<FriendCheckResp> check(@Valid FriendCheckReq friendCheckReq) {
        RequestInfo requestInfo = RequestHolder.getThreadLocal();
        return ApiResult.success(userApplyService.check(requestInfo.getUid(), friendCheckReq.getUidList()));
    }


    @ApiOperation("用户申请列表")
    @GetMapping("/page")
    public ApiResult<PageBaseResp<UserApplyPageResp>> page(@Valid PageBaseReq pageBaseReq) {
        RequestInfo requestInfo = RequestHolder.getThreadLocal();
        return ApiResult.success(userApplyService.pageApply(requestInfo.getUid(), pageBaseReq));
    }


    @ApiOperation("用户申请列表未读数")
    @GetMapping("/unread")
    public ApiResult<FriendUnreadResp> unread() {
        RequestInfo requestInfo = RequestHolder.getThreadLocal();
        return ApiResult.success(userApplyService.unread(requestInfo.getUid()));
    }

    @ApiOperation("好友申请")
    @PostMapping
    public ApiResult<Void> apply(@Valid @RequestBody FriendApplyReq req) {
        RequestInfo requestInfo = RequestHolder.getThreadLocal();
        userApplyService.apply(requestInfo.getUid(), req);
        return ApiResult.success();
    }

    @ApiOperation("好友申请审批")
    @PutMapping
    public ApiResult<Void> applyApproval(@Valid @RequestBody ApplyApprovalReq req) {
        RequestInfo requestInfo = RequestHolder.getThreadLocal();
        userApplyService.applyApproval(requestInfo.getUid(), req.getApplyId());
        return ApiResult.success();
    }



}

